thin.imports('/public/home/css/global.project.css');

thin.imports('/public/configure/conf.minfo.js');
//thin.imports('/public/modules/upload.js');

thin.imports('/public/plug/wxshare/jweixin-1.2.0.js', function() {
	thin.imports('/public/plug/wxshare/wx.api.js');
});

thin.use(function() {
	//var upload = thin.uploadFiles;

	/*$('[layout-mark=uploadFile]').on('change', function(e) {
		var picture = upload.getPicture(e);
		if(picture) {
			$(this).parent().children('img').attr('src', picture);
			var u = $(this).attr('data-u');
			var fileInput = this.files[0];
			var form = new FormData();
			form.append("file", fileInput);
			form.append("name", "file");
			form.append("dir", 'upload');
			upload.getSrc('/api?common.upload', form, window[u]);
			this.parentNode.reset();
		}
	});*/

	$('[layout-mark=tab-item]').off('click').on('click', function(e) {
		var e = e || window.event;
		e.stopPropagation();
		var that = $(this),
			itor = that.attr('data-itor');
		that.addClass('weui-bar__item--on').siblings('a').removeClass('weui-bar__item--on');
		$(itor).addClass('weui-tab__bd-item--active').siblings('div').removeClass('weui-tab__bd-item--active');
		checkTab(itor);
		return false;
	});

	$('#btn-share').on('click', function(e) {
		var e = e || window.event;
		e.stopPropagation();
		if(!jude_wx) {
			$.showLoading();
			getJsval(function() {
				$.hideLoading();
				$('#share-modal').popup();
				jude_wx = true;
			});
		} else {
			$('#share-modal').popup();
		}
		return false;
	});

	// 路由
	checkLocation();
});

function cker(hash, id) {
	$('#' + id).html('');
	checkLocation(hash);
}

function __complete_macc(res) {
	$.hideLoading();
	if(res.status == 200) {
		$('#acc-price').text(res.data);
	} else {
		$.toptip(res.error, 'error');
	}
}

var __getdata_minfobase = {},
	jude_wx = false;

var data_mobile = '';

function __complete_minfobase(res) {
	$.hideLoading();
	if(res.status == 200) {
		var role;
		if(res.data.role == 1) {
			role = '创业者';
		} else if(res.data.role == 2) {
			role = '个人天使投资者';
		} else if(res.data.role == 3) {
			role = '机构投资者';
		}
		$('#mbinfo').html(res.data.info.city + '  ' + role + '<br />' + res.data.info.company);
		data_mobile = res.data.info.mobile;
	} else {
		$.toptip(res.error, 'error');
	}
}

var jude_cert = false,
	jude_mbinfo = false,
	jude_memsec = false;

// 路由
function checkLocationCallback(hash) {
	if(hash == 'member' || hash == 'mychat') {
		if(!jude_mbinfo) {
			$.showLoading();
			__getdata_minfobase['model'] = 1;
			factory.request('_minfo_base');
			jude_mbinfo = true;
		}

		if(hash == 'mychat') {
			$('#member-template').show().siblings('.warp').hide();
			$('a[data-itor=#msg-modal]').trigger('click');
		}
	}

	if(hash == 'memsec') {
		if(!jude_memsec) {
			$.showLoading();
			thin.imports('/public/home/resource/mem-sec.js', function() {
				setTimeout(function() {
					$.hideLoading();
				}, 1200);
			});
			jude_memsec = true;
		}
	}
	
	if (hash == 'cert') {
		if(!jude_cert) {
			$.showLoading();
			thin.imports('/public/home/resource/mem-cert.js');
			jude_cert = true;
		}
	}

	if(/acc$/gi.test(hash)) {
		$.showLoading();
		factory.request('_m_acc');
	}

	if(hash == 'msg-modal') {
		$('#member-template').show();
		$('[data-itor=#msg-modal]').trigger('click');
	}

	if(hash == 'repass') {
		$('#repass-tpl-view').html($('#repass-tpl-modal').html());
		setTimeout(function() {
			$('#ipt-re-mobile').val(data_mobile);
		}, 800);
	}

	if(hash == 'editmobile') {
		$('#editmobile-tpl-view').html($('#editmobile-tpl-modal').html());
		$('#ipt-rm-oldmobile').val(data_mobile);
	}
}

var jude_msgpage = false;

function checkTab(itor) {
	if(/msg-modal/gi.test(itor)) {
		checkLocationTitle('我的消息');
		if(!jude_msgpage) {
			$.showLoading();
			thin.imports('/public/home/resource/mem-msg.js');
			jude_msgpage = true;
		}
	}

	if(/tab4/gi.test(itor)) {
		checkLocationTitle('会员中心');
		//checkLocation('member');
	}
}